#include "XYControlWidget.h"
const int ICONSIZE = 40;
XYControlWidget::XYControlWidget(QWidget *parent) :
    QWidget(parent)
{
    initContent();
    initConnection();
}

void XYControlWidget::initConnection()
{
    connect(pushButtonMotorBackward, SIGNAL(pressed()), this, SIGNAL(moveBackward()));
    connect(pushButtonMotorBackward, SIGNAL(released()), this, SIGNAL(moveBackwardStop()));

    connect(pushButtonMotorForward, SIGNAL(pressed()), this, SIGNAL(moveForward()));
    connect(pushButtonMotorForward, SIGNAL(released()), this, SIGNAL(moveForwardStop()));

    connect(pushButtonMotorLeft, SIGNAL(pressed()), this, SIGNAL(moveLeft()));
    connect(pushButtonMotorLeft, SIGNAL(released()), this, SIGNAL(moveLeftStop()));

    connect(pushButtonMotorRight, SIGNAL(pressed()), this, SIGNAL(moveRight()));
    connect(pushButtonMotorRight, SIGNAL(released()), this, SIGNAL(moveRightStop()));

    connect(pushButtonStop, SIGNAL(pressed()), this, SIGNAL(stop()));
}

void XYControlWidget::initContent()
{
    gridLayout = new QGridLayout(this);
    gridLayout->setSpacing(1);
    pushButtonMotorBackward = new QPushButton(this);
    pushButtonMotorBackward->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorBackward->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon;
    icon.addFile(QStringLiteral(":/StageControlCommon/res/up.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorBackward->setIcon(icon);
    pushButtonMotorBackward->setIconSize(QSize(ICONSIZE, ICONSIZE));

    gridLayout->addWidget(pushButtonMotorBackward, 0, 1, 1, 1);

    pushButtonMotorLeft = new QPushButton(this);
    pushButtonMotorLeft->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorLeft->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon1;
    icon1.addFile(QStringLiteral(":/StageControlCommon/res/left.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorLeft->setIcon(icon1);
    pushButtonMotorLeft->setIconSize(QSize(ICONSIZE, ICONSIZE));

    gridLayout->addWidget(pushButtonMotorLeft, 1, 0, 1, 1);

    pushButtonStop = new QPushButton(this);
    pushButtonStop->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonStop->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon2;
    icon2.addFile(QStringLiteral(":/StageControlCommon/res/stop.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonStop->setIcon(icon2);
    pushButtonStop->setIconSize(QSize(ICONSIZE, ICONSIZE));

    gridLayout->addWidget(pushButtonStop, 1, 1, 1, 1);

    pushButtonMotorRight = new QPushButton(this);
    pushButtonMotorRight->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorRight->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon3;
    icon3.addFile(QStringLiteral(":/StageControlCommon/res/right.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorRight->setIcon(icon3);
    pushButtonMotorRight->setIconSize(QSize(ICONSIZE, ICONSIZE));

    gridLayout->addWidget(pushButtonMotorRight, 1, 2, 1, 1);

    pushButtonMotorForward = new QPushButton(this);
    pushButtonMotorForward->setMinimumSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorForward->setMaximumSize(QSize(ICONSIZE, ICONSIZE));
    QIcon icon4;
    icon4.addFile(QStringLiteral(":/StageControlCommon/res/down.png"), QSize(), QIcon::Normal, QIcon::Off);
    pushButtonMotorForward->setIcon(icon4);
    pushButtonMotorForward->setIconSize(QSize(ICONSIZE, ICONSIZE));
    pushButtonMotorForward->setFlat(false);

    gridLayout->addWidget(pushButtonMotorForward, 2, 1, 1, 1);
    setLayout(gridLayout);

    QSizePolicy policy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    setSizePolicy(policy);
}


XYControlWidget::~XYControlWidget()
{
}
